package cn.com.fssg.platform.base.handler.impl.cl.xunlian;

import cn.com.fssg.platform.base.handler.InterfaceHandler;
import cn.com.fssg.platform.biz.BizUtil;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class ClXunlianQueryApplyInterfaceHandler implements InterfaceHandler {

    private NamedParameterJdbcTemplate jdbcTemplate = BizUtil.cur().tenantJdbcTemplate("CJRLHHConnString");
//    @Autowired
//    private NamedParameterJdbcTemplate jdbcTemplate;


    @Override
    public Object run(HttpServletRequest request, JSONObject jsonObject) throws Exception {
        List<Map<String, Object>> list = null;
        String userId = BizUtil.cur().curUserId();
        /*String querySql = "select r.role_code, r.role_name from pxone.su_user_role ur " +
                "left join pxone.su_role r on ur.role_id = r.id  where ur.user_id = :userId";
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("userId", userId);
        try {

            List<Map<String, Object>> roleList = jdbcTemplate.queryForList(querySql, paramMap);
            boolean isNomal = false;
            if (!CollectionUtils.isEmpty(roleList)) {
                for (Map<String, Object> role : roleList) {
                    String roleCode = (String) role.get("role_code");
                    if ("regular_user".equals(roleCode) || "weixin_user".equals(roleCode)) {
                        isNomal = true;
                        break;
                    }
                }

            }
            if (isNomal) {
                String userQuery = "select * from pxone.su_user where id = :userId";
                Map<String, Object> userMap = jdbcTemplate.queryForMap(userQuery, paramMap);
                String phone = ObjectUtils.isEmpty(userMap.get("phone"))? null : (String)userMap.get("phone");
                if (!ObjectUtils.isEmpty(phone)) {
                    querySql = "select * from cl_apply_xunlian where cjr_jhr_phone = :cjr_jhr_phone";
                    paramMap.put("cjr_jhr_phone", phone);
                    list = jdbcTemplate.queryForList(querySql, paramMap);
                } else {
                    return userMap;
                }
            }
        } catch (Exception e) {
            return "jdbc:" + jdbcTemplate + ";" + e.getMessage();
        }*/
//        return list;
        return "userId:" + userId;
    }
}
